package com.xxx.video.dynamic.adapters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.utils.ResourcesUtils;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.dynamic.beans.ReceiverFriendListBean;

import butterknife.BindView;

public class MyGetFriendRequestAdapter extends BaseRecycleViewAdapter<ReceiverFriendListBean.PageBean.ListBean, MyGetFriendRequestAdapter.MyHolder> {


    public MyGetFriendRequestAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_my_get_friend_request;
    }

    public class MyHolder extends BaseViewHolder {
        @BindView(R.id.iv_item_my_get_friend_request_avatar)
        ImageView ivItemMyGetFriendRequestAvatar;
        @BindView(R.id.tv_item_my_get_friend_request_name)
        TextView tvItemMyGetFriendRequestName;
        @BindView(R.id.tv_item_my_get_friend_request_status)
        TextView tvItemMyGetFriendRequestStatus;
        @BindView(R.id.tv_item_my_get_friend_request_status_un_agree_recall)
        TextView tvItemMyGetFriendRequestStatusUnAgreeRecall;
        @BindView(R.id.tv_item_my_get_friend_request_status_un_agree_tip)
        TextView tvItemMyGetFriendRequestStatusUnAgreeTip;
        @BindView(R.id.tv_item_my_get_friend_request_status_un_agree)
        LinearLayout tvItemMyGetFriendRequestStatusUnAgree;

        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            ReceiverFriendListBean.PageBean.ListBean listBean = getItem(position);
            /*
             * avatar
             */
            Glide.with(context).load(ResourcesUtils.getInstance().getImagePath(listBean.fPicurl))
                    .apply(new RequestOptions().circleCrop()
                            .placeholder(R.drawable.icon_default_avatar)
                            .error(R.drawable.icon_default_avatar)
                    ).into(ivItemMyGetFriendRequestAvatar);
            /*
             * name
             */
            tvItemMyGetFriendRequestName.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.fUserName));
            tvItemMyGetFriendRequestStatus.setVisibility(View.GONE);
            tvItemMyGetFriendRequestStatusUnAgree.setVisibility(View.GONE);
            if (listBean.fStatus == 0) {
                tvItemMyGetFriendRequestStatusUnAgree.setVisibility(View.VISIBLE);
            } else if (listBean.fStatus == 1) {
                tvItemMyGetFriendRequestStatus.setVisibility(View.VISIBLE);
                tvItemMyGetFriendRequestStatus.setText(StringUtils.getInstance().getString(R.string.item_friend_alreaady));
            }
            tvItemMyGetFriendRequestStatusUnAgreeRecall.setOnClickListener(v -> {
                /*
                 * un agree
                 */
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(listBean, position, 1);
                }
                data.remove(position);
                notifyDataSetChanged();
            });
            tvItemMyGetFriendRequestStatusUnAgreeTip.setOnClickListener(v -> {
                /*
                 * agree
                 */
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(listBean, position, 2);
                }
                listBean.fStatus=1;

                tvItemMyGetFriendRequestStatusUnAgree.setVisibility(View.GONE);
                tvItemMyGetFriendRequestStatus.setVisibility(View.VISIBLE);
                tvItemMyGetFriendRequestStatus.setText(StringUtils.getInstance().getString(R.string.item_friend_alreaady));
            });
        }
    }
}
